from pyspark.context import SparkContext

sc = SparkContext(master='local',appName='word_count')

stu_score_rdd = sc.textFile('../../data/stu_score.txt')


stu_score_rdd.flatMap(lambda line:line.split(',')[-1].split('|')).foreach(print)

def flat_map_fun(line):
    stu_split = line.split(',')

    stu_info = stu_split[:-1]

    stu = ','.join(stu_info)

    sco_list = stu_split[-1].split('|')

    stu_score = [f'{stu},{sco}' for sco in sco_list]
    return stu_score

stu_scores_rdd = stu_score_rdd.flatMap(flat_map_fun)
stu_scores_rdd.foreach(print)